package com.icinfo.cloud.provider.punish.controller;

import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.dto.PrintDocHtmlQueryDto;
import com.icinfo.cloud.provider.punish.dto.PrintDocQueryDto;
import com.icinfo.cloud.provider.punish.print.vo.PrintDocumentVo;
import com.icinfo.cloud.provider.punish.service.IDocCommonOperateService;
import com.icinfo.cloud.provider.punish.service.ISimpleCaseService;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.RealNameCheckDto;
import com.icinfo.cloud.provider.punish.ucase.caseregister.vo.RealNameCheckVo;
import com.icinfo.framework.common.web.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *
 * 描述：文书通用操作
 *
 * @author shishnegyao
 * @date 2022-06-27 09:39
 */
@RestController
@RequestMapping("/app/common")
public class DocCommonOperateController {

    @Resource
    private IDocCommonOperateService docCommonOperateService;

    @Resource
    private ISimpleCaseService simpleCaseService;
    /**
     * 【v1.3.0】获取打印文书的html内容
     *
     * @author lxj
     * @result Result
     */
    @PostMapping("getPrintDocHtmlContent")
    public Result getPrintDocHtmlContent(@RequestBody @Validated PrintDocHtmlQueryDto queryDto) {
        String url = docCommonOperateService.getPrintDocHtmlContent(queryDto);
        return Result.success("", url);
    }


    /**
     * 【v1.3.4】获取打印内容
     *
     * @param dto 打印文书参数
     * @return
     */
    @PostMapping("/getPrintDocContent")
    public Result<PrintDocumentVo> getPrintDocContent(@Validated @RequestBody PrintDocQueryDto dto) {
        return Result.success(docCommonOperateService.getPrintDocContent(dto));
    }

    /**
     * 【V1.7.2】描述：实名认证
     *
     * @param checkDto 检查dto
     * @return {@link Result<RealNameCheckVo> }
     * @author shishengyao
     * @date 2022/05/17
     */
    @PostMapping("/checkRealName")
    public Result<Object> checkRealName(@RequestBody @Validated RealNameCheckDto checkDto) {
        boolean rightIdNo = BaseUtil.isRightIdNo(checkDto.getIdCard());
        if (!rightIdNo){
            return Result.error("身份证格式错误！");
        }
        if (simpleCaseService.checkRealName(checkDto.getRealName(),checkDto.getIdCard())){
            return Result.success("校验成功");
        }else{
            return Result.error("校验失败");
        }
    }
}
